<?php


namespace app\bock\type;


use app\bock\type\action\Operating;
use app\bock\type\bock\BockF;
use app\bock\type\bock\BockL;
use app\bock\type\pre\NowBock;
use app\bock\type\stack\PanelStack;

class SenceBock
{
    /**
     * @var Panel
     */
    protected $panel;

    /**
     * @var NowBock
     */
    protected $nowBock;

    /**
     * @var PanelStack
     */
    protected $panelStack;

    /**
     * @var Operating
     */
    protected $operate;

    public function __construct()
    {
        $this->panel = new Panel(10,20);
        $this->nowBock = new NowBock();
        $this->panelStack = new PanelStack();
        $this->operate = new Operating();


        $this->nowBock->setPanel($this->panel);

        // 堆块关联面板用于初始化
        $this->panelStack->setPanel($this->panel);

        $this->operate->setNowBock($this->nowBock);
        $this->operate->setPanelStack($this->panelStack);

    }

    /**
     * 启动场景
     */
    public function run()
    {

        try {
            while (true)
            {
                $this->operate->input();

                $this->panel->flush();
                $this->nowBock->down($this->panelStack);
                usleep(1000000);
            }
        }catch (\Exception $exception){
            echo $exception->getMessage();
        }

    }
}